package com.hzl.lease.web.admin.schedule;


import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.hzl.lease.model.entity.LeaseAgreement;
import com.hzl.lease.model.enums.LeaseStatus;
import com.hzl.lease.web.admin.service.LeaseAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

//定时任务类
@Component
public class ScheduledTasks {
    /*
    *   定时检查租约的过期状态
    *   判断是否过期了条件：
    *           ①status租约状态是2或者5
    *           ②lease_end_data 租约到期时间 < 当前时间
    * */

    @Autowired
    private LeaseAgreementService leaseAgreementService;

  //  @Scheduled(cron = "* 30 23 * * ?")  //表示每天的23:30分相应一次
    public void scheduledTask() {
        leaseAgreementService.update(new LambdaUpdateWrapper<LeaseAgreement>()
                .le(LeaseAgreement::getLeaseEndDate,new Date())
                .in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING)
                .set(LeaseAgreement::getStatus, LeaseStatus.WITHDRAWING));
        System.out.println("定时查询租约过期状态！");
    }

}


